cmake_minimum_required(VERSION 3.20)

#function(with_mt_if_msvc target)
#    if (MSVC)
#        # Generator expressions
#        set(_mt "/MT$<$<CONFIG:Debug>:d")
#        get_target_property(_options ${target} COMPILE_OPTIONS)
#        if (_options)
#            # message(STATUS "${target} COMPILE_OPTIONS=${_options}")
#            if (${_options} MATCHES "/MD")
#                string(REGEX REPLACE "/MD" "/MT" _options "${_options}")
#            else ()
#                set(_options "${_options} ${_mt}")
#            endif ()
#        else ()
#            set(_options "${_mt}")
#        endif ()
#        get_target_property(_type ${target} TYPE)
#        # 判断 ${target}是否为静态库
#        if (_type STREQUAL "STATIC_LIBRARY")
#            # 静态库将/MT选项加入INTERFACE_COMPILE_OPTIONS
#            target_compile_options(${target} PUBLIC "${_options}")
#        else ()
#            target_compile_options(${target} PRIVATE "${_options}")
#        endif ()
#        # Cleanup temporary variables.
#        unset(_mt)
#        unset(_options)
#        message(STATUS "target ${target} use static runtime /MT")
#    endif (MSVC)
#endfunction()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(BoostAsioEchoServer BoostAsioEchoServer.cc)
target_link_libraries(BoostAsioEchoServer ${Boost_LIBRARIES})

add_executable(BoostAsioEchoServerV2 BoostAsioEchoServerV2.cc)
target_link_libraries(BoostAsioEchoServerV2 ${Boost_LIBRARIES})


if (MSVC)
    # 设置MT/MTd
    set_property(TARGET BoostAsioEchoServerV2 PROPERTY
            MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

    set_property(TARGET BoostAsioEchoServer PROPERTY
            MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif (MSVC)